public class Demo15 {
    public static void main(String[] args) throws InterruptedException {
        Object block1 = new Object();
        Object block2 = new Object();
        Object block3 = new Object();

        Thread a = new Thread( () -> {
            Thread.currentThread().setName("a");
            try{
                synchronized (block1) {
                    block1.wait();
                }
                System.out.println(Thread.currentThread().getName());

            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        Thread b = new Thread(() -> {
            Thread.currentThread().setName("b");
            try{
                synchronized (block2) {
                    block2.wait();
                }
                System.out.print(Thread.currentThread().getName()+",");

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (block1) {
                block1.notify();
            }
        });
        Thread c = new Thread(() -> {
            Thread.currentThread().setName("c");
            try{
                synchronized (block3) {
                    block3.wait();
                }
                System.out.print(Thread.currentThread().getName()+",");
                synchronized (block2) {
                    block2.notify();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        a.start();
        b.start();
        c.start();
        Thread.sleep(1000);
        synchronized (block3) {
            block3.notify();
        }
    }
}
